<?php

class Login extends CI_Controller {

	public function __construct()  
    {  
        parent::__construct();  
    }

	public function index($message = FALSE) {

		$data['title'] = '登陆';
		if ($message == 'please') {
			$data['message'] = '请先登录';
		} elseif ($message == 'error') {
			$data['message'] = '账号或密码错误';
		}
		$this->load->view('software/login', $data);
	}

	public function check() {
		$this->load->helper('url');
		$request = $this->input->post();
		$user = array(
			'user' => iconv('UTF-8', 'GBK', $request['user']),
			'password' => iconv('UTF-8', 'GBK', $request['password']),
		);
		$this->load->model('metro_model');
		$result = $this->metro_model->_check_login($user);
		if ($result === 1) {
			$user_cookie = array(
				'name' => 'user',
				'value' => $user['user'],
				'expire' => 0,
				'path' => '/'
			);
			print_r($user_cookie);
			$this->input->set_cookie($user_cookie);
            redirect(base_url());
		} else {
			redirect('login/index/error');
		}
	}

}

?>